home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / Utils / NuPopUpUtils < prev   
Text File  |  1993-03-30  |  5KB  |  181 lines

  1. unit NuPopUpUtils;
  2.  
  3. interface
  4.  
  5.     {Create a new, empty menu for the specified pop up. Get rid of it only with DisposeDPopUpMenu.}
  6.     function NewDPopUpMenu (item: Integer; title: Str255): MenuHandle;
  7.     {Dispose of the menu for the specified pop up. Any submenus are also disposed. Create submenus with NewMenu!}
  8.     procedure DisposeDPopUpMenu (item: Integer);
  9.  
  10.     {Load a MENU resource for the specified pop up. Any submenus are also loaded. Rid only with ReleaseDPopUpMenu.}
  11.     procedure GetDPopUpMenu (item: Integer);
  12.     {Release the menu for the specified pop up. Any submenus are also released. Create submenus with GetMenu!}
  13.     procedure ReleaseDPopUpMenu (item: Integer);
  14.  
  15.     {Return the menu handle for the specified pop up. Works for both kinds…}
  16.     function GetDPopUpMHandle (item: Integer): MenuHandle;
  17.  
  18.     {Return the menu ID for the specified pop up. Works for both kinds…}
  19.     function GetDPopUpMenuID (item: Integer): Integer;
  20.  
  21.     {Return the item count, or 0 for a nil menu handle.}
  22.     function GetDPopupItemCount (item: Integer): Integer;
  23.  
  24.     {Track an invisible pop up at the specified point.}
  25.     procedure TrackInvisibleDPopUp (item: Integer; localPt: Point);
  26.  
  27.     {Force an editable pop up to capture its associated TE field’s contents.}
  28.     {You need to do this before the pop up may have to be redrawn, like when you cover it with}
  29.     {another window. Note that you specify the dialog item ID of the pop up, not it’s TE field.}
  30.     procedure CapturePopUpTE (whichPopUp: Integer);
  31.  
  32. implementation
  33.  
  34.     uses
  35.         NuDialogUtils;
  36.  
  37.     function GetDPopUpMenuID (item: Integer): Integer;
  38.         type
  39.             popupPrivateData = record
  40.                     mHandle: MenuHandle;
  41.                     mID: Integer;
  42.                 end;
  43.             popupPrivateDataPtr = ^popupPrivateData;
  44.             popupPrivateDataHdl = ^popupPrivateDataPtr;
  45.     begin
  46.         GetDPopUpMenuID := popupPrivateDataHdl(GetDControlHandle(item)^^.contrlData)^^.mID;
  47.     end;
  48.  
  49.     function NewDPopUpMenu (item: Integer; title: Str255): MenuHandle;
  50.         var
  51.             menuID: Integer;
  52.             menuH: MenuHandle;
  53.     begin
  54.         menuID := GetDPopUpMenuID(item);
  55.         menuH := NewMenu(menuID, title);
  56.         if menuH <> nil then
  57.             InsertMenu(menuH, -1);
  58.         NewDPopUpMenu := menuH;
  59.     end;
  60.  
  61.     type
  62.         RemoveKind = (Dispose, Release);
  63.  
  64.     procedure RecursiveRemoveMenu (menuH: MenuHandle; kind: RemoveKind);
  65.         var
  66.             i: Integer;
  67.             cmd, mark: Char;
  68.     begin
  69.         if menuH <> nil then
  70.             begin
  71.                 for i := 1 to CountMItems(menuH) do
  72.                     begin
  73.                         GetItemMark(menuH, i, mark);
  74.                         GetItemCmd(menuH, i, cmd);
  75.                         if cmd = CHR($1B) then
  76.                             RecursiveRemoveMenu(GetMHandle(ORD(mark)), kind);
  77.                     end;
  78.                 DeleteMenu(menuH^^.menuID);
  79.                 case kind of
  80.                     Dispose: 
  81.                         DisposeMenu(menuH);
  82.                     Release: 
  83.                         ReleaseResource(Handle(menuH));
  84.                 {no otherwise…}
  85.                 end;
  86.             end;
  87.     end;
  88.  
  89.     procedure DisposeDPopUpMenu (item: Integer);
  90.         var
  91.             menuID: Integer;
  92.             menuH: MenuHandle;
  93.     begin
  94.         menuID := GetDPopUpMenuID(item);
  95.         menuH := GetMHandle(menuID);
  96.         RecursiveRemoveMenu(menuH, Dispose);
  97.     end;
  98.  
  99.     procedure RecursiveGetMenu (menuH: MenuHandle);
  100.         var
  101.             i: Integer;
  102.             cmd, mark: Char;
  103.     begin
  104.         if menuH <> nil then
  105.             begin
  106.                 InsertMenu(menuH, -1);
  107.                 for i := 1 to CountMItems(menuH) do
  108.                     begin
  109.                         GetItemMark(menuH, i, mark);
  110.                         GetItemCmd(menuH, i, cmd);
  111.                         if cmd = CHR($1B) then
  112.                             RecursiveGetMenu(GetMenu(ORD(mark)));
  113.                     end;
  114.             end;
  115.     end;
  116.  
  117.     procedure GetDPopUpMenu (item: Integer);
  118.         var
  119.             menuID: Integer;
  120.             menuH: MenuHandle;
  121.     begin
  122.         menuID := GetDPopUpMenuID(item);
  123.         menuH := GetMenu(menuID);
  124.         RecursiveGetMenu(menuH);
  125.     end;
  126.  
  127.     procedure ReleaseDPopUpMenu (item: Integer);
  128.         var
  129.             menuID: Integer;
  130.             menuH: MenuHandle;
  131.     begin
  132.         menuID := GetDPopUpMenuID(item);
  133.         menuH := MenuHandle(GetResource('MENU', menuID));
  134.         RecursiveRemoveMenu(menuH, Release);
  135.     end;
  136.  
  137.     function GetDPopUpMHandle (item: Integer): MenuHandle;
  138.         var
  139.             menuID: Integer;
  140.     begin
  141.         menuID := GetDPopUpMenuID(item);
  142.         GetDPopUpMHandle := GetMHandle(menuID);
  143.     end;
  144.  
  145.     function GetDPopupItemCount (item: Integer): Integer;
  146.         var
  147.             myMH: MenuHandle;
  148.     begin
  149.         myMH := GetDPopUpMHandle(item);
  150.         if myMH = nil then
  151.             GetDPopupItemCount := 0        {This isn’t the value the ROM would give you!}
  152.         else
  153.             GetDPopupItemCount := CountMItems(myMH);
  154.     end;
  155.  
  156.     procedure TrackInvisibleDPopUp (item: Integer; localPt: Point);
  157.         var
  158.             controlH: ControlHandle;
  159.             value: Integer;
  160.     begin
  161.         controlH := GetDControlHandle(item);
  162.         MoveControl(controlH, localPt.h, localPt.v);
  163.         value := TrackControl(controlH, localPt, POINTER(-1));
  164.     end;
  165.  
  166.     procedure CapturePopUpTE (whichPopUp: Integer);
  167.         var
  168.             theDialog: DialogPtr;
  169.             itemKind: Integer;
  170.             itemHandle: Handle;
  171.             itemRect: Rect;
  172.             saveHilite: Byte;
  173.     begin
  174.         GetPort(GrafPtr(theDialog));
  175.         GetDItem(theDialog, whichPopUp, itemKind, itemHandle, itemRect);
  176.         saveHilite := ControlHandle(itemHandle)^^.contrlHilite;
  177.         HiliteControl(ControlHandle(itemHandle), 1);
  178.         HiliteControl(ControlHandle(itemHandle), saveHilite);
  179.     end;
  180.  
  181. end.